<?php
class BGCrypt {
    public static $rounds = 15;
    public static function pw_hash($pw) {
        $salt=sprintf('$2y$%02d$',self::$rounds);
        $salt .= substr(strtr(base64_encode(openssl_random_pseudo_bytes(18)),'+','.'),0,22);
        //$chars='./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
        //for($i=0;$i<22;$i++) $salt.=$chars[mt_rand(0,63)];
        return crypt($pw,$salt);
    }
    public static function pw_verify($pw,$saved_hash) {
        return (crypt($pw,$saved_hash) === $saved_hash);
    }
}
?>
